package LeetCode;

public class LC_165_CompareVersionNumbers {

    public static void main(String[] args) {

    }

    static class Solution {
        public int compareVersion(String version1, String version2) {
            String[] ver1 = version1.split("\\.");
            String[] ver2 = version2.split("\\.");
            int len1 = ver1.length;
            int len2 = ver2.length;
            int len = 0;
            if (len2 <= len1) len = len2;
            else len = len1;
            int num1;
            int num2;
            int i = 0;

            while (i < len) {
                num1 = Integer.valueOf(ver1[i]);
                num2 = Integer.valueOf(ver2[i]);
                if (num1 == num2) i++;
                else if (num1 < num2) return -1;
                else return 1;
            }

            while (len1 > i) {
                if (Integer.valueOf(ver1[i++]) != 0) return 1;
            }

            i = len;

            while (len2 > i) {
                if (Integer.valueOf(ver2[i++]) != 0) return -1;
            }
            return 0;
        }
    }

}